package com.shanghaionstar.user.presenter;

import android.os.Bundle;

import com.onstar.cn.common.log.LogManager;
import com.onstar.cn.framework.mvp.base.IMVPScheduler;
import com.onstar.cn.framework.mvp.base.IMVPView;
import com.onstar.cn.framework.mvp.base.core.BaseActivity;
import com.onstar.cn.framework.mvp.base.core.BasePresenter;
import com.onstar.cn.mag.enumtype.CategoryType;
import com.onstar.cn.more.response.GetHelpListResponseType;
import com.shanghaionstar.R;
import com.shanghaionstar.activity.webview.handler.CommonWebViewActivity;
import com.shanghaionstar.activity.webview.handler.DetailContentWebHandler;
import com.shanghaionstar.activity.webview.handler.IWebType;
import com.shanghaionstar.activity.webview.handler.WebDataEntity;
import com.shanghaionstar.user.iview.IHelpListView;
import com.shanghaionstar.user.service.HelpService;

/**
 * Created by 7828wc on 16/7/1.
 */
public class HelpListPresenter extends BasePresenter<GetHelpListResponseType> {
    private IHelpListView helpView;
    private LogManager log = LogManager.getInstance();
    private GetHelpListResponseType mListResponse;
    private HelpService mHelpService;

    public HelpListPresenter(IMVPScheduler mvpScheduler) {
        super(mvpScheduler);
    }

    @Override
    public void setView(IMVPView<GetHelpListResponseType> view) {
        super.setView(view);
        this.helpView = (IHelpListView) view;
        mHelpService = new HelpService(helpView.onActivity());
        super.setServiceProvider(mHelpService);
    }

    public void onItemClick(int pos, GetHelpListResponseType responseType, BaseActivity mActivity) {
        try {
            if (responseType != null) {
                String detailId = responseType.getContentHeaderList().get(pos).getContentNUM();
                String detailTitle = responseType.getContentHeaderList().get(pos).getTitle();
//                HelpDetailFragment helpDetailFragment = new HelpDetailFragment();
//                Intent it = new Intent(mActivity, CommonWebViewActivity.class);
                Bundle bun = new Bundle();
                WebDataEntity entity = new WebDataEntity();
                entity.setClzName(DetailContentWebHandler.class.getName());
                entity.what = IWebType.TYPE_CONTENT_ID;
                entity.setTopTitle(helpView.onActivity().getString(R.string.help_detail_title));
                bun.putString("detailId", detailId);
                bun.putSerializable("categoryType",CategoryType.ONSTAR_SYBZ);
                bun.putString("detailTitle", detailTitle);
                bun.putParcelable(IWebType.KEY_WEB_DATA,entity);
                CommonWebViewActivity.launchCommonWeb(mActivity,bun,entity);
//                it.putExtras(bun);
//                mActivity.startActivity(it);
//                helpDetailFragment.setArguments(bun);
//                mActivity.changeFragment(mActivity.getSupportFragmentManager(), helpDetailFragment, HelpDetailFragment.class, true);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


//    public void showLandingPage() {
//        landingPageDBService = new LandingPageDBService(helpView.onActivity());
//        mListResponse = landingPageDBService.getLandingPage();
//        if (mListResponse != null) {
//            File localFile = new File(mListResponse.getFilePath());
//            if (localFile.exists()) {
//                isShowLandingPage = true;
//                helpView.showLandingPage(mListResponse);
//                log.d("Get local file success,waiting for view refresh");
//            } else {
//                isShowLandingPage = false;
//                landingPageDBService.delete(mListResponse.getId());
//            }
//        } else {
//            isShowLandingPage = false;
//        }
//    }
//
//    public void downloadLandingPage(LandingsPageEntity object) {
//        LandingsPageEntity landingsPageEntity = mHelpService.downloadImage(object);
//        landingPageDBService.insert(landingsPageEntity);
//        helpView.showLandingPage(landingsPageEntity);
//    }
//
//    public void deleteLandingPage() {
//        if (mListResponse != null) {
//            landingPageDBService.delete(mListResponse.getId());
//        }
//        //获取Landing Page失败，删除本地所有Cache图片
//        landingPageDBService.deleteExpireFile();
//    }
}
